# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort testfiles testfiles1 testvirtmem testP1P2 test1 t2c1 t2c2 t3c1 t3c2 t3c3

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles

test1.o: test1.c
	$(CC) $(CFLAGS) -c test1.c
test1: test1.o start.o
	$(LD) $(LDFLAGS) start.o test1.o -o test1.coff
	../bin/coff2noff test1.coff test1

t2c1.o: t2c1.c
	$(CC) $(CFLAGS) -c t2c1.c
t2c1: t2c1.o start.o
	$(LD) $(LDFLAGS) start.o t2c1.o -o t2c1.coff
	../bin/coff2noff t2c1.coff t2c1

t2c2.o: t2c2.c
	$(CC) $(CFLAGS) -c t2c2.c
t2c2: t2c2.o start.o
	$(LD) $(LDFLAGS) start.o t2c2.o -o t2c2.coff
	../bin/coff2noff t2c2.coff t2c2


t3c1.o: t3c1.c
	$(CC) $(CFLAGS) -c t3c1.c
t3c1: t3c1.o start.o
	$(LD) $(LDFLAGS) start.o t3c1.o -o t3c1.coff
	../bin/coff2noff t3c1.coff t3c1

t3c2.o: t3c2.c
	$(CC) $(CFLAGS) -c t3c2.c
t3c2: t3c2.o start.o
	$(LD) $(LDFLAGS) start.o t3c2.o -o t3c2.coff
	../bin/coff2noff t3c2.coff t3c2

t3c3.o: t3c3.c
	$(CC) $(CFLAGS) -c t3c3.c
t3c3: t3c3.o start.o
	$(LD) $(LDFLAGS) start.o t3c3.o -o t3c3.coff
	../bin/coff2noff t3c3.coff t3c3




testfiles1.o: testfiles1.c
	$(CC) $(CFLAGS) -c testfiles1.c
testfiles1: testfiles1.o start.o
	$(LD) $(LDFLAGS) start.o testfiles1.o -o testfiles1.coff
	../bin/coff2noff testfiles1.coff testfiles1
testvirtmem.o: testvirtmem.c
	$(CC) $(CFLAGS) -c testvirtmem.c
testvirtmem: testvirtmem.o start.o
	$(LD) $(LDFLAGS) start.o testvirtmem.o -o testvirtmem.coff
	../bin/coff2noff testvirtmem.coff testvirtmem

testP1P2.o: testP1P2.c
	$(CC) $(CFLAGS) -c testP1P2.c
testP1P2: testP1P2.o start.o
	$(LD) $(LDFLAGS) start.o testP1P2.o -o testP1P2.coff
	../bin/coff2noff testP1P2.coff testP1P2

clean:
	rm -f *.o *.coff
